package com.xinz.activity;

import com.xinz.Constants;

import android.content.Intent;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;


public class LoginActivity extends BaseActivity{

	LinearLayout globalLayout;
	
	TextView accountText;
	
	TextView passwordText;
	
	TextView registerText;
	
	EditText accountEdit;
	
	EditText passwordEdit;
	
	Button loginButton;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		globalLayout = new LinearLayout(this);
		globalLayout.setOrientation(LinearLayout.VERTICAL);
		
		accountText = new TextView(globalLayout.getContext());
		accountText.setText(getString(R.string.text_account));
		passwordText = new TextView(globalLayout.getContext());
		passwordText.setText(getString(R.string.text_password));
		
		registerText = new TextView(globalLayout.getContext());
		registerText.setText(getString(R.string.text_register));
		
		accountEdit = new EditText(globalLayout.getContext());
		accountEdit.setEms(10);
		passwordEdit = new EditText(globalLayout.getContext());
		passwordEdit.setEms(10);
		passwordEdit.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
		
		loginButton = new Button(globalLayout.getContext());
		loginButton.setText(getString(R.string.text_login));
		
		LinearLayout acountLinearLayout = new LinearLayout(globalLayout.getContext());
		acountLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
		LinearLayout.LayoutParams accountLayoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		accountLayoutParams.setMargins(200, 50, 0, 0);
		
		LinearLayout.LayoutParams accountTextLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		acountLinearLayout.addView(accountText, accountTextLayoutParams);
		
		LinearLayout.LayoutParams accountEditLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		acountLinearLayout.addView(accountEdit, accountEditLayoutParams);
		
		globalLayout.addView(acountLinearLayout, accountLayoutParams);
		
		
		
		LinearLayout passwordLinearLayout = new LinearLayout(globalLayout.getContext());
		passwordLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
		LinearLayout.LayoutParams passwordLayoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		passwordLayoutParams.setMargins(200, 50, 0, 0);
		
		LinearLayout.LayoutParams passwordTextLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		passwordLinearLayout.addView(passwordText, passwordTextLayoutParams);
		
		LinearLayout.LayoutParams passwordEditLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		passwordLinearLayout.addView(passwordEdit, passwordEditLayoutParams);
		
		globalLayout.addView(passwordLinearLayout, passwordLayoutParams);
		
		RelativeLayout loginRelativeLayout = new RelativeLayout(globalLayout.getContext());
		RelativeLayout.LayoutParams loginLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

		RelativeLayout.LayoutParams loginButtonLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		loginButtonLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
		
		loginRelativeLayout.addView(loginButton, loginButtonLayoutParams);
		
		globalLayout.addView(loginRelativeLayout, loginLayoutParams);
		
		
		addContentView(globalLayout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		
		loginButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// 单击后跳转到新界面（Activity）
				Intent intent = new Intent(LoginActivity.this, SpotActivity.class);
				intent.putExtra(Constants.ACCOUNT, accountEdit.getText().toString());
				intent.putExtra(Constants.PASSWORD, passwordEdit.getText().toString());
				startActivity(intent);
			}
		});
	}
	
}
